<template>
  <el-button type="danger" @click="delRow" v-if="showButton" :loading="loading">撤销</el-button>
</template>

<script>
import request from "@/utils/request";
import {deleteShipment} from "@/api/shipmentV2";

export default {
  name: 'DelShipmentButton',
  props: {
    id: {
      required: true
    },
    data: {
      type: Object,
    },
  },
  computed: {
    showButton(){
      if(!this.data){
        return false
      }
      return !!this.data.canDelete
    }
  },
  data(){
    return {
      loading: false,
    }
  },
  methods: {
    delRow(){
      this.$confirm('','确认撤销该货件单?')
        .then(res=>{
          this.loading = true
          deleteShipment(this.id)
            .then(res=>{
              this.loading = false
              if(res.error === 0){
                this.$successMessage(res.message)
                this.$emit('changeRow')
                this.$emit('delRow')
              }else{
                this.$errorMessage(res.message)
              }
            })
        })
        .catch(res=>{
          console.log(res)
        })
    },
  }
}

</script>

<style scoped lang="scss">

</style>
